/*
 * @Author: duanguang
 * @Date: 2021-11-24 22:04:07
 * @LastEditTime: 2022-03-03 09:28:14
 * @LastEditors: duanguang
 * @Description:  git 仓库数据表
 * @FilePath: /legions-server/app/model/branch_apply.ts
 * 「扫去窗上的尘埃，才可以看到窗外的美景。」
 */
import { Model, Document, Schema } from '.';
import { Application } from 'egg';

/** 分支申请实体 */
export class BranchApply {
    /** 项目名称 */
    repository_name: string = '';

    project_id:string=''

    /** 分支名称 */
    branch_name: string = '';

    /** 来源分支名称 */
    source_branch: string = '';

    /** 分支类型 */
    branch_type: string = ''
    
    /** 仓库地址 */
    repository_https: string = ''
        
    /** 分支用途 */
    branch_usage: string = ''
    
    /** 审批人 */
    assign_members: string = ''
    
    /** 审批人id */
    assign_members_id: string = ''
    
    /** 审查状态 
     * 
     * 0表示待审核
     * 
     * 1表示审核通过
     * 
     * 2 驳回
     */
    audit_status:string =''
    
    /** 创建人id */
    creator_id: string = ''
    
    /** 创建人 */
    creator: string = ''

     /** gitlab 仓库项目id */
    gitlab_project_id: string = ''
    
    /** 项目分组信息 */
    gitlab_project_group:string =''
    
    /** 创建时间 */
    create_time: number = new Date().getTime();

    
    /** 修改时间 */
    update_time: number = new Date().getTime();
}

export interface IBranchApplyModel extends Document, BranchApply {}

export default function BranchApplyModel(
    app: Application,
): Model<IBranchApplyModel> {
    const mongoose = app.mongoose;
    const Schema = mongoose.Schema;
    const branchApplySchema: Schema = new Schema({
        repository_name: { type: String },
        project_id: { type: String },
        branch_name: { type: String },
        source_branch: { type: String },
        branch_type: { type: String },
        repository_https: { type: String },
        branch_usage: { type: String },
        assign_members: { type: String },
        assign_members_id: { type: String },
        audit_status: { type: String },
        creator_id: { type: String },
        creator: { type: String },
        gitlab_project_id: { type: String },
        gitlab_project_group: { type: String },
        create_time: { type: Number },
        update_time: { type: Number },
    }, {
        timestamps: { updatedAt: 'update_time', createdAt: 'create_time' },
    });
    return mongoose.model<IBranchApplyModel>(
        'brach_apply',
        branchApplySchema,
    );
}
